package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.ChannelRoleService;
import com.yixun.qfbao.apidto.EditChannelRoleReqDto;
import com.yixun.qfbao.apidto.EditChannelRoleResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.EditChannelRoleReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 编辑角色
 * @author guifang.weng
 * @create 2017-11-22 15:52
 **/
@Service("editChannelRoleHander")
public class EditChannelRoleHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(EditChannelRoleHander.class);

    @Autowired
    private ChannelRoleService channelRoleService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<EditChannelRoleResDto> res = new BaseResponseDTO<>();
        EditChannelRoleReqVo reqVo = (EditChannelRoleReqVo) reqDto;
        EditChannelRoleReqDto editChannelRoleReqDto = reqVo.getParams();
        try {
            EditChannelRoleResDto resDto = channelRoleService.editChannelRole(editChannelRoleReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("EditChannelRoleHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("编辑角色失败");
        }
        return res;
    }
}
